• An MGLStyleAnnotation represents a single point, line, or polygon shape that can be displayed on an MGLMapView within a geographical coordinate space.

    Do not create instances of MGLStyleAnnotation directly. Instead, create an instance of MGLCircleStyleAnnotation, MGLLineStyleAnnotation, MGLPolygonStyleAnnotation, or MGLSymbolStyleAnnotation and use -[MGLAnnotationController addShape:] or -[MGLStyleAnnotationController addShapes:] to add an MGLStyleAnnotation to a map view.

    See more

    Declaration

    Objective-C

    @interface MGLStyleAnnotation : NSObject

    Swift

    class MGLStyleAnnotation : NSObject
  • An MGLCircleStyleAnnotation is a type of style layer annotation that renders one or more filled circles on the map.

    To display a circle style annotation on a map, use one of the initializers below to create a circle style annotation object. Then, use -[MGLCircleAnnotationController add:] to add the annotation to a circle style annotation controller.

    Example

    func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
       let circleAnnotationController = MGLCircleAnnotationController(mapView: self.mapView)
       let circle = MGLCircleStyleAnnotation(center: CLLocationCoordinate2D(latitude: 59.31, longitude: 18.06), radius: 3.0, color: .blue)
       circle.opacity = 0.5
       circleAnnotationController.add(circle)
    }
    
    See more

    Declaration

    Objective-C

    @interface MGLCircleStyleAnnotation : MGLStyleAnnotation

    Swift

    class MGLCircleStyleAnnotation : MGLStyleAnnotation
  • An MGLLineStyleAnnotation is a type of style layer annotation that renders one or more stroked polylines on the map.

    To display a line style annotation on a map, use one of the initializers below to create a line style annotation object. Then, use -[MGLLineAnnotationController add:] to add the annotation to a line style annotation controller.

    Example

    func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
       let lineAnnotationController = MGLLineAnnotationController(mapView: self.mapView)
    
       let lineCoordinates = [
           CLLocationCoordinate2D(latitude: 59, longitude: 18),
           CLLocationCoordinate2D(latitude: 60, longitude: 20)
       ]
    
       let line = MGLLineStyleAnnotation(coordinates: lineCoordinates, count: UInt(lineCoordinates.count))
       line.color = .purple
       lineAnnotationController.add(line)
    }
    
    See more

    Declaration

    Objective-C

    @interface MGLLineStyleAnnotation : MGLStyleAnnotation

    Swift

    class MGLLineStyleAnnotation : MGLStyleAnnotation
  • An MGLPolygonStyleAnnotation is a type of style layer annotation that renders one or more polygons on the map.

    To display a line style annotation on a map, use one of the initializers below to create a polygon style annotation object. Then, use -[MGLPolygonAnnotationController add:] to add the annotation to a polygon style annotation controller.

    Example

    func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
       let polygonAnnotationController = MGLPolygonAnnotationController(mapView: self.mapView)
    
       let polygonCoordinates = [
           CLLocationCoordinate2DMake(59, 18),
           CLLocationCoordinate2DMake(62, 19),
           CLLocationCoordinate2DMake(54, 20),
           CLLocationCoordinate2DMake(59, 18)
       ]
    
       let polygon = MGLPolygonStyleAnnotation(coordinates: polygonCoordinates, count: UInt(polygonCoordinates.count))
       polygon.fillOutlineColor = .red
       polygonAnnotationController.add(polygon)
    }
    
    See more

    Declaration

    Objective-C

    @interface MGLPolygonStyleAnnotation : MGLStyleAnnotation

    Swift

    class MGLPolygonStyleAnnotation : MGLStyleAnnotation
  • An MGLSymbolStyleAnnotation is a type of style layer annotation that renders both an icon and text label at a specified coordinate.

    To display a symbol style annotation on a map, use one of the initializers below to create a symbol style annotation object. Then, use -[MGLSymbolAnnotationController add:] to add the annotation to a symbol style annotation controller.

    If rendering an icon, first add an image to the map style’s sprite using the -[MGLStyle setImage:forName:] method within the Mapbox Maps SDK for iOS.

    Example

    func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
       let attraction = UIImage(named: "attraction")
    
       if let styleImage = attraction {
           self.mapView.style?.setImage(styleImage, forName: "attraction")
       }
    
       let symbolAnnotationController = MGLSymbolAnnotationController(mapView: self.mapView)
    
       let symbol = MGLSymbolStyleAnnotation(coordinate: CLLocationCoordinate2DMake(59, 18));
       symbol.iconImageName = "attraction"
       symbol.text = "This is a cool place!"
       symbol.textFontSize = 16
       symbolAnnotationController.add(symbol)
    }
    
    See more

    Declaration

    Objective-C

    @interface MGLSymbolStyleAnnotation : MGLStyleAnnotation

    Swift

    class MGLSymbolStyleAnnotation : MGLStyleAnnotation